package com.ebring.shareEducation.utils;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * Created by Cola
 * Date  2018/8/21 11:50
 *
 *
 * UUID生成工具类
 */
public class UuidUtils {

    //  定义所有的数字字符组成的串
    final static char[] numberChar = {
            '0' , '1' , '2' , '3' , '4' , '5' ,
            '6' , '7' , '8' , '9'
    };


    /**
     * 自动生成32位的UUid，对应数据库的主键id进行插入用。
     * @return
     */
    public static String getUUID() {

        return UUID.randomUUID().toString().replace("-", "");
    }

    /**
     * 产生长度为length的随机字符串（只包括数字）
     * @param length
     * @return
     */
    public static String getNumberId(int length) {
        StringBuffer respStr = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            respStr.append(numberChar[random.nextInt(10)]);
        }
        return respStr.toString();
    }

    public static String getRandomZm() {
        String randomcode = "";
        for(int i=0;i<6;i++){
            //52个字母与6个大小写字母间的符号；范围为91~96
            int value = (int)(Math.random()*58+65);
            while(value>=91 && value<=96)
                value = (int)(Math.random()*58+65);
            randomcode = randomcode + (char)value;
        }
        return randomcode;


    }
    public static String getRandom() {
        int i = (int)(Math.random()*900 + 100);
        return Integer.toString(i);
    }

    public static String getdate() {
        Date dNow = new Date( );
        SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");
        return ft.format(dNow);
    }

    public static String getdates() {
        Date dNow = new Date( );
        SimpleDateFormat ft = new SimpleDateFormat ("yyyyMMddhhmmss");
        return ft.format(dNow);
    }


    public static void main(String[] args) {
    }

    /**
     * 产生长度为length的随机字符串（只包括数字）
     * @param length
     * @return
     */
    public static String getNumberIds(int length) {
        StringBuffer respStr = new StringBuffer();
        Random random = new Random();
        Date dNow = new Date( );
        SimpleDateFormat ft = new SimpleDateFormat ("yyyyMMddhhmmss");
        String dd=ft.format(dNow);
        respStr.append(dd);
        for (int i = 0; i < length; i++) {
            respStr.append(numberChar[random.nextInt(10)]);
        }

        return respStr.toString();
    }

}
